package sessionBeans;
import java.util.Set;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import entityBeans.Address;
import entityBeans.Contact;
import entityBeans.ContactGroup;
import entityBeans.PhoneNumber;

@Stateless(mappedName = "ContactBeanEntity")
public class GestionContactBeanEntity implements GestionContactRemote {

	@PersistenceContext
	EntityManager em;

	@Override
	public String coucouContact(String nomContact) {
		return "Coucou, "+nomContact;
	}

	@Override
	public void addContact(String firstname,String lastname,String email, Address ad, 
			Set<PhoneNumber> phones, Set<ContactGroup> books, String siret) {
		Contact contact=new Contact();
		contact.setFirstName(firstname);
		contact.setLastName(lastname);
		contact.setEmail(email);
		contact.setAdd(ad);
		contact.setProfiles(phones);
		contact.setBooks(books);
		
		em.persist(contact);
	}

	@Override
	public String findContactNameById(long id) {
		Contact contact=em.find(Contact.class, id);
		return contact.getLastName() +", "+contact.getFirstName();
	}
	  
	
	
	
	
	
}
